package com.reebake.ideal.security.oauth2.vo;

import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import lombok.Data;

import java.util.Date;
import java.util.Map;
import java.util.Set;

@Data
public class RegisteredClientVO {

    private String id;
    private String clientId;
    private Date clientIdIssuedAt;
    private Date clientSecretExpiresAt;
    private String clientName;
    private Set<String> clientAuthenticationMethods;
    private Set<String> authorizationGrantTypes;
    private String redirectUris;
    private String postLogoutRedirectUris;
    private String scopes;
    private String clientSettings;
    private String tokenSettings;

    private Boolean requireAuthorizationConsent = true;

    public Boolean getRequireAuthorizationConsent() {
        if (StrUtil.isNotBlank(clientSettings)) {
            Map<String, Object> map = JSONUtil.toBean(this.clientSettings, new TypeReference<Map<String, Object>>() {
            }, false);
            return (Boolean) map.get("settings.client.require-authorization-consent");
        }
        return this.requireAuthorizationConsent;
    }
}
